package com.zelma.mywebsocket.ws;

import org.springframework.stereotype.Component;

import javax.servlet.http.HttpSession;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;

@Component
public class GetHttpSession extends ServerEndpointConfig.Configurator {
    @Override
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
        //获取当前httpsession
        HttpSession session= (HttpSession) request.getHttpSession();
        //放进EndpoiontConfig
        sec.getUserProperties().put(HttpSession.class.getName(),session);
    }
}
